home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / RCS / main.c,v < prev    next >
Encoding:
Text File  |  1992-06-16  |  46.6 KB  |  2,046 lines

  1. head     1.23;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.23
  10. date     92.06.16.13.02.30;  author jhh;  state Exp;
  11. branches ;
  12. next     1.22;
  13.  
  14. 1.22
  15. date     92.04.21.21.09.00;  author shirriff;  state Exp;
  16. branches ;
  17. next     1.21;
  18.  
  19. 1.21
  20. date     89.08.10.16.44.28;  author douglis;  state Exp;
  21. branches ;
  22. next     1.20;
  23.  
  24. 1.20
  25. date     89.08.10.16.12.19;  author douglis;  state Exp;
  26. branches ;
  27. next     1.19;
  28.  
  29. 1.19
  30. date     89.07.23.17.33.21;  author nelson;  state Exp;
  31. branches ;
  32. next     1.18;
  33.  
  34. 1.18
  35. date     89.06.16.08.30.54;  author brent;  state Exp;
  36. branches ;
  37. next     1.17;
  38.  
  39. 1.17
  40. date     89.06.02.13.54.14;  author brent;  state Exp;
  41. branches ;
  42. next     1.16;
  43.  
  44. 1.16
  45. date     89.06.02.13.50.05;  author brent;  state Exp;
  46. branches ;
  47. next     1.15;
  48.  
  49. 1.15
  50. date     89.04.10.16.33.01;  author mgbaker;  state Exp;
  51. branches ;
  52. next     1.14;
  53.  
  54. 1.14
  55. date     89.03.23.09.52.17;  author brent;  state Exp;
  56. branches ;
  57. next     1.13;
  58.  
  59. 1.13
  60. date     89.02.21.10.04.47;  author brent;  state Exp;
  61. branches ;
  62. next     1.12;
  63.  
  64. 1.12
  65. date     88.10.17.08.59.47;  author ouster;  state Exp;
  66. branches ;
  67. next     1.11;
  68.  
  69. 1.11
  70. date     88.09.28.11.41.58;  author mendel;  state Exp;
  71. branches ;
  72. next     1.10;
  73.  
  74. 1.10
  75. date     88.08.30.09.53.33;  author brent;  state Exp;
  76. branches ;
  77. next     1.9;
  78.  
  79. 1.9
  80. date     88.08.26.16.34.13;  author mendel;  state Exp;
  81. branches ;
  82. next     1.8;
  83.  
  84. 1.8
  85. date     88.08.16.11.47.09;  author mendel;  state Exp;
  86. branches ;
  87. next     1.7;
  88.  
  89. 1.7
  90. date     88.08.16.11.24.33;  author mendel;  state Exp;
  91. branches ;
  92. next     1.6;
  93.  
  94. 1.6
  95. date     88.06.26.12.14.02;  author mendel;  state Exp;
  96. branches ;
  97. next     1.5;
  98.  
  99. 1.5
  100. date     88.06.01.16.32.57;  author brent;  state Exp;
  101. branches ;
  102. next     1.4;
  103.  
  104. 1.4
  105. date     88.05.16.09.11.28;  author brent;  state Exp;
  106. branches ;
  107. next     1.3;
  108.  
  109. 1.3
  110. date     87.12.13.18.57.23;  author andrew;  state Exp;
  111. branches ;
  112. next     1.2;
  113.  
  114. 1.2
  115. date     87.10.22.21.27.09;  author deboor;  state Exp;
  116. branches ;
  117. next     1.1;
  118.  
  119. 1.1
  120. date     87.10.19.15.58.56;  author deboor;  state Exp;
  121. branches ;
  122. next     ;
  123.  
  124.  
  125. desc
  126. @@
  127.  
  128.  
  129. 1.23
  130. log
  131. @changed the configuration file to be /etc/ipServer.config
  132. @
  133. text
  134. @/* 
  135.  * main.c --
  136.  *    
  137.  *    This file contains the initialization and file-system interface
  138.  *    routines for the Sprite Internet Protocol Server.
  139.  *
  140.  * Copyright 1987 Regents of the University of California
  141.  * All rights reserved.
  142.  * Permission to use, copy, modify, and distribute this
  143.  * software and its documentation for any purpose and without
  144.  * fee is hereby granted, provided that the above copyright
  145.  * notice appear in all copies.  The University of California
  146.  * makes no representations about the suitability of this
  147.  * software for any purpose.  It is provided "as is" without
  148.  * express or implied warranty.
  149.  */
  150.  
  151. #ifndef lint
  152. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer.new/RCS/main.c,v 1.22 92/04/21 21:09:00 shirriff Exp Locker: jhh $ SPRITE (Berkeley)";
  153. #endif not lint
  154.  
  155.  
  156. #include "sprite.h"
  157. #include "inet.h"
  158. #include "ipServer.h"
  159. #include "stat.h"
  160. #include "socket.h"
  161. #include "route.h"
  162. #include "raw.h"
  163. #include "ip.h"
  164. #include "icmp.h"
  165. #include "tcp.h"
  166. #include "udp.h"
  167.  
  168. #include "netInet.h"
  169. #include "dev/pdev.h"
  170. #include "spriteTime.h"
  171. #include "proc.h"
  172.  
  173. #include "option.h"
  174. #include <stdio.h>
  175. #include "fs.h"
  176. #include "sys/file.h"
  177.  
  178. /*
  179.  * Command line options.
  180.  */
  181.  
  182. Boolean ips_Debug = FALSE;
  183. static Boolean detach = TRUE;
  184. static char defaultConfigFile[100] = "/etc/ipServer.config";
  185. static char *configFile = defaultConfigFile;
  186. static char *ipAddress = (char *) NULL;
  187.  
  188. static Option optionArray[] = {
  189.     {OPT_TRUE,   "d", (Address)&ips_Debug, "Turn on debugging output"},
  190.     {OPT_STRING, "c", (Address)&configFile, "Name of configuration file"},
  191.     {OPT_STRING, "i", (Address)&ipAddress, "IP address"},
  192.     {OPT_FALSE,  "b", (Address)&detach, "Don't run in background"},
  193. };
  194. static int numOptions = sizeof(optionArray) / sizeof(Option);
  195.  
  196. char        myHostName[100];
  197.  
  198. typedef struct Sock_PrivInfo *PrivPtr;
  199.  
  200. static void     PdevRequestHandler();
  201. static void     PdevControlHandler();
  202. static int     PrintMemStats();
  203. static int     ToggleDebug();
  204. static int     PrintInfoAndDebug();
  205. #ifdef TEST_DISCONNECT
  206. static int ToggleDisconnect();
  207. int    ips_Disconnect = 0;
  208. #endif
  209.  
  210. /*
  211.  *----------------------------------------------------------------------
  212.  *
  213.  * main --
  214.  *
  215.  *      The main program for the Internet Protocol Server. The
  216.  *      initialization routines of the important modules are called to
  217.  *      set up their data structures. The socket pseudo-devices and the
  218.  *      network device are opened and the FS dispatcher is called to
  219.  *      process events from them.
  220.  *
  221.  * Results:
  222.  *    None.
  223.  *
  224.  * Side effects:
  225.  *    Files are opened. Signal handlers are established.
  226.  *
  227.  *----------------------------------------------------------------------
  228.  */
  229.  
  230. void
  231. main(argc, argv)
  232.     int        argc;
  233.     char    **argv;
  234. {
  235.     int            streamID;
  236.     Sig_Action        sigAction;
  237.     Proc_PID        pid;
  238.     char        deviceName[100];
  239. #ifdef DEBUG
  240.     extern int        Sys_PrintNumCalls();
  241. #endif DEBUG
  242.     extern int        memAllowFreeingFree;
  243.  
  244.     /*
  245.      * Turn on checks for duplicate frees in the memory allocator.
  246.      */
  247.  
  248.     memAllowFreeingFree = 0;
  249.  
  250.     IP_MemBin();
  251.     TCP_MemBin();
  252.     Mem_Bin(sizeof(Sock_BufDataInfo));
  253.     Mem_Bin(sizeof(Sock_SharedInfo));
  254.     Mem_Bin(sizeof(Sock_PrivInfo));
  255.     Mem_SetPrintProc(fprintf, (ClientData)stderr);
  256.  
  257.     argc = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  258.  
  259.     /*
  260.      * Print debugging information when the signals are caught. 
  261.      */
  262.  
  263. #define SetHandler(sig, routine) \
  264.     sigAction.action = SIG_HANDLE_ACTION; \
  265.     sigAction.handler = routine; \
  266.     sigAction.sigHoldMask = 1 << (sig-1); \
  267.     if (Sig_SetAction(sig, &sigAction, NULL) != SUCCESS) { \
  268.     (void) fprintf(stderr, "main: can't set signal handler %d\n", sig); \
  269.     }
  270.  
  271.     SetHandler(25, ToggleDebug);
  272.     SetHandler(26, Stat_PrintInfo);
  273.     SetHandler(27, Sock_PrintInfo);
  274. #ifdef TEST_DISCONNECT
  275.     SetHandler(28, ToggleDisconnect);
  276. #else
  277.     SetHandler(28, PrintMemStats);
  278. #endif
  279. #ifdef DEBUG
  280.     SetHandler(29, Sys_PrintNumCalls);
  281. #endif DEBUG
  282.     SetHandler(30, PrintInfoAndDebug);
  283.  
  284.  
  285.     setlinebuf(stderr);
  286. #ifndef sun4
  287.     {
  288.     char    *Version();
  289.     (void) fprintf(stderr, "Sprite Internet Protocol Server: %s\n", 
  290.             Version());
  291.     }
  292. #endif sun4
  293.  
  294.     if (gethostname(myHostName, sizeof(myHostName)) != 0) {
  295.     panic("Can't find my hostname\n");
  296.     }
  297.  
  298.     Rte_AddressInit(myHostName, configFile, ipAddress);
  299.  
  300.     Sock_Init();
  301.  
  302.     Sys_GetTimeOfDay(&stats.startTime, (int *) NULL, (Boolean *) NULL);
  303.  
  304.     IP_Init();
  305.     ICMP_Init();
  306.     UDP_Init();
  307.     TCP_Init(stats.startTime.seconds);
  308.  
  309.  
  310.     /*
  311.      * Open the pseudo-devices that correspond to the stream (TCP), 
  312.      * datagram (UDP) and raw (IP) socket abstractions. The raw socket
  313.      * is opened with 0600 permission so only set-root-uid programs can 
  314.      * access it.
  315.      */
  316.  
  317.     (void) umask(0);
  318.  
  319.     (void) sprintf(deviceName, INET_STREAM_NAME_FORMAT, myHostName);
  320.     streamID = open(deviceName, O_RDONLY|O_CREAT|O_MASTER, 0666);
  321.     if (streamID < 0) {
  322.     perror(deviceName);
  323.     exit(1);
  324.     }
  325.     Fs_EventHandlerCreate(streamID, FS_READABLE, PdevControlHandler, 
  326.             (ClientData) TCP_PROTO_INDEX);
  327.  
  328.  
  329.     (void) sprintf(deviceName, INET_DGRAM_NAME_FORMAT, myHostName);
  330.     streamID = open(deviceName, O_RDONLY|O_CREAT|O_MASTER, 0666);
  331.     if (streamID < 0) {
  332.     perror(deviceName);
  333.     exit(1);
  334.     }
  335.     Fs_EventHandlerCreate(streamID, FS_READABLE, PdevControlHandler,
  336.             (ClientData) UDP_PROTO_INDEX);
  337.  
  338.  
  339.     (void) sprintf(deviceName, INET_RAW_NAME_FORMAT, myHostName);
  340.     streamID = open(deviceName, O_RDONLY|O_CREAT|O_MASTER, 0600);
  341.     if (streamID < 0) {
  342.     perror(deviceName);
  343.     exit(1);
  344.     }
  345.     Fs_EventHandlerCreate(streamID, FS_READABLE, PdevControlHandler, 
  346.             (ClientData) RAW_PROTO_INDEX);
  347.  
  348.  
  349.     pid = getpid(); 
  350.     (void) fprintf(stderr, "PID = %x\n", pid);
  351.  
  352.  
  353.     /*
  354.      * Now that everything is set up, run in the background if the
  355.      * debug flag is not set.
  356.      */
  357.     if (!ips_Debug && detach) {
  358.     Proc_Detach(0);
  359.     }
  360.  
  361.  
  362.     /*
  363.      * Everything's initialized. Start processing events from the
  364.      * the socket pseudo-devices and the network device.
  365.      */
  366.     while (TRUE) {
  367.     stats.misc.dispatchLoop++;
  368.     Fs_Dispatch();
  369.     IP_DelayedOutput();
  370.     }
  371. }
  372.  
  373.  
  374. /*
  375.  *----------------------------------------------------------------------
  376.  *
  377.  * PdevControlHandler --
  378.  *
  379.  *    This routine handles the creation of new pseudo-device connections 
  380.  *    to the server from client programs. It is called from the
  381.  *    FS dispatcher whenever one of "stream/datagram/raw" control streams
  382.  *    become readable. A socket is created for the connection. Further
  383.  *    requests on the new stream will be handled by PdevRequestHandler()
  384.  *    (or UdpRequestHandler)
  385.  *
  386.  * Results:
  387.  *    None.
  388.  *
  389.  * Side effects:
  390.  *    A new socket is created for the connection.
  391.  *
  392.  *----------------------------------------------------------------------
  393.  */
  394.  
  395. static void
  396. PdevControlHandler(clientData, streamID, eventMask)
  397.     ClientData    clientData;    /* Protocol index # for the socket type. */
  398.     int        streamID;    /* ID of stream that became readable, writable,
  399.                  * or has an exception condition ready. */
  400.     int        eventMask;    /* Mask to show what event happened. A combo of
  401.                  * Should be just FS_READABLE. */
  402. {
  403.     ReturnStatus    status;
  404.     Pdev_Notify        notify;
  405.     Pdev_SetBufArgs    bufArgs;
  406.     SockPdevState    *sockPdevPtr;
  407.     int            amount;
  408.     int            state;
  409.     int            reqBufSize;
  410.     int            bigWrites;
  411.     int            writeBehind;
  412.     void        (*handler)();
  413.  
  414.     if (!(eventMask & FS_READABLE)) {
  415.     panic("PdevControlHandler: bad event mask %x\n", eventMask);
  416.     }
  417.  
  418.     /*
  419.      * Read the notify message from the control stream.
  420.      */
  421.  
  422.     amount = read(streamID, (Address)¬ify, sizeof(notify));
  423.     if (amount < 0) {
  424.     perror("PdevControlHandler: read notify");
  425.     exit(1);
  426.     } else if (amount != sizeof(notify)) {
  427.     panic("PdevControlHandler: short read (%d) of the notify\n", amount);
  428.     exit(1);
  429.     } else if (notify.magic != PDEV_NOTIFY_MAGIC) {
  430.     panic("PdevControlHandler: bad magic # (%x) in the notify\n", 
  431.         notify.magic);
  432.     exit(1);
  433.     }
  434.  
  435.     sockPdevPtr = (SockPdevState *)malloc(sizeof(SockPdevState));
  436.     switch ((int)clientData) {
  437.     case TCP_PROTO_INDEX:
  438.         sockPdevPtr->reqBufSize = TCP_REQUEST_BUF_SIZE;
  439.         sockPdevPtr->protoIndex = TCP_PROTO_INDEX;
  440.         bigWrites = TRUE;
  441.         writeBehind = FALSE;
  442.         break;
  443.     case UDP_PROTO_INDEX:
  444.         sockPdevPtr->reqBufSize = UDP_REQUEST_BUF_SIZE;
  445.         sockPdevPtr->protoIndex = UDP_PROTO_INDEX;
  446.         bigWrites = FALSE;
  447.         writeBehind = UDP_WRITE_BEHIND;
  448.         break;
  449.     case RAW_PROTO_INDEX:
  450.         sockPdevPtr->reqBufSize = RAW_REQUEST_BUF_SIZE;
  451.         sockPdevPtr->protoIndex = RAW_PROTO_INDEX;
  452.         bigWrites = FALSE;
  453.         writeBehind = FALSE;
  454.         break;
  455.     }
  456.     /*
  457.      * Allocate the pseudo-device request buffer, leaving room at the
  458.      * front to create packet headers, and adding enough room to account
  459.      * for the pdev message header in front of the data.
  460.      * Make sure the request buffer is a multiple of the word size.
  461.      * (The kernel should do this.)
  462.      */
  463.     sockPdevPtr->reqBufSize += sizeof(Pdev_Request) + sizeof(int);
  464.     sockPdevPtr->reqBufSize &= ~(sizeof(int) - 1);
  465.     sockPdevPtr->requestBuf = (Address) malloc(sockPdevPtr->reqBufSize +
  466.                         IPS_ROOM_FOR_HEADERS);
  467.     bufArgs.requestBufAddr = sockPdevPtr->requestBuf + IPS_ROOM_FOR_HEADERS;
  468.     bufArgs.requestBufSize = sockPdevPtr->reqBufSize;
  469.     bufArgs.readBufAddr = (Address) NULL;
  470.     bufArgs.readBufSize = 0;
  471.     status = Fs_IOControl(notify.newStreamID, IOC_PDEV_SET_BUF,
  472.         sizeof(bufArgs), (Address) &bufArgs, 
  473.         0, (Address) NULL);
  474.     if (status != SUCCESS){
  475.     Stat_PrintMsg(status, "PdevControlHandler: ioc set buf");
  476.     exit(1);
  477.     }
  478.     status = Fs_IOControl(notify.newStreamID, IOC_PDEV_BIG_WRITES,
  479.         sizeof(state), (Address) &bigWrites, 
  480.         0, (Address) NULL);
  481.     if (status != SUCCESS){
  482.     Stat_PrintMsg(status, "PdevControlHandler: ioc big write");
  483.     exit(1);
  484.     }
  485.     status = Fs_IOControl(notify.newStreamID, IOC_PDEV_WRITE_BEHIND,
  486.         sizeof(state), (Address) &writeBehind, 
  487.         0, (Address) NULL);
  488.     if (status != SUCCESS){
  489.     Stat_PrintMsg(status, "PdevControlHandler: ioc write behind");
  490.     exit(1);
  491.     }
  492.  
  493.     Fs_EventHandlerCreate(notify.newStreamID, FS_READABLE, PdevRequestHandler,
  494.                 (ClientData)sockPdevPtr);
  495. }
  496.  
  497.  
  498. static int origFirstByte;
  499.  
  500. /*
  501.  *----------------------------------------------------------------------
  502.  *
  503.  * PdevRequestHandler --
  504.  *
  505.  *    Handle an request from a client accessing a socket pseudo-device.
  506.  *    We read a short message off the request stream that indicates
  507.  *    where in the buffer the next request message(s) are.  Depending
  508.  *    on the client's operation, we may allocate a return data block
  509.  *    that gets filled in by the socket routine.  We reply with a
  510.  *    return status for the client's system call and, optionally, the
  511.  *    return data block.
  512.  *
  513.  * Results:
  514.  *    None.
  515.  *
  516.  * Side effects:
  517.  *    The operation-specific routines may cause side-effects.
  518.  *
  519.  *----------------------------------------------------------------------
  520.  */
  521.  
  522. static void
  523. PdevRequestHandler(clientData, streamID, eventMask)
  524.     ClientData    clientData;    /* Token passed the Sock_ routines to identify
  525.                  * a socket. */
  526.     int        streamID;    /* ID of stream that became readable, writable
  527.                  * or has an exception condition ready. */
  528.     int        eventMask;    /* Mask to show what event happened.
  529.                  * Must be FS_READABLE. */
  530. {
  531.     ReturnStatus    status;
  532.     register Pdev_Request    *requestPtr;
  533.     Pdev_Reply    reply;
  534.     Pdev_BufPtrs    bufPtrs;
  535.     int            amount;
  536.     Address        requestData;
  537.     int            messageSize;
  538.     int            replySize;
  539.     Pdev_Op        operation;
  540.     /*
  541.      * All requests, except PDEV_OPEN, get passed the socket private pointer
  542.      * as the client data from Fs_Dispatch.
  543.      */
  544.     Sock_PrivInfo    *privPtr = (Sock_PrivInfo *)clientData;
  545.  
  546.  
  547.     if (!(eventMask & FS_READABLE)) {
  548.     panic("PdevRequestHandler: bad event mask %x\n", 
  549.                 eventMask);
  550.     }
  551.  
  552.     /*
  553.      * Read the short request header that tells us where in the buffer
  554.      * the next request message is.  Check size and magic number.
  555.      */
  556.  
  557.     amount = read(streamID, (Address)&bufPtrs, sizeof(bufPtrs));
  558.     if (amount  != sizeof(bufPtrs)) {
  559.     perror("PdevRequestHandler: get ptr ioctl");
  560.     exit(1);
  561.     } else if (bufPtrs.magic != PDEV_BUF_PTR_MAGIC) {
  562.     panic("PdevControlHandler: bad magic # (%x) in the bufPtrs\n", 
  563.         bufPtrs.magic);
  564.     exit(1);
  565.     } 
  566.  
  567.     origFirstByte = bufPtrs.requestFirstByte;
  568.     while (bufPtrs.requestFirstByte < bufPtrs.requestLastByte) {
  569.     requestPtr = (Pdev_Request *)
  570.             &bufPtrs.requestAddr[bufPtrs.requestFirstByte];
  571.     if (requestPtr->hdr.magic != PDEV_REQUEST_MAGIC) {
  572.         printf("PdevControlHandler: bad magic # (%x) comitting hari-kari\n",
  573.             requestPtr->hdr.magic);
  574. #ifdef notdef
  575.         /*
  576.          * This will put us more cleanly into the debugger than a panic
  577.          * will.
  578.          */
  579.         *(int *)0 = 100;
  580.         exit(1);
  581. #endif
  582.         /*
  583.          * Hack to attempt to get around the server lieing to us by
  584.          * telling us that there is more data than there really is.
  585.          */
  586.         bufPtrs.requestFirstByte = bufPtrs.requestLastByte + 1;
  587.         break;
  588.     } 
  589.     requestData = (Address)((Address)requestPtr + sizeof(Pdev_Request));
  590.     reply.replySize = 0;
  591.     reply.replyBuf = (Address) NULL;
  592.  
  593.     /*
  594.      * Decode the operation and call a routine for the operation.
  595.      * The operation handler may overwrite the request header with
  596.      * a packet header, so we are careful not to use anything from
  597.      * the request header after calling the service procedure.
  598.      */
  599.     messageSize = requestPtr->hdr.messageSize;
  600.     replySize = requestPtr->hdr.replySize;
  601.     operation = requestPtr->hdr.operation;
  602.     switch (operation) {
  603.  
  604.  
  605.         case PDEV_OPEN: {
  606.             /*
  607.              * Create a new socket structure. If the open was 
  608.              * successful, create an event handler to handle future 
  609.              * requests on the stream.  Sock_Open returns a token 
  610.              * for the new socket, which is associated with the event 
  611.              * handler for the socket's stream.
  612.              *
  613.              * The first arg. to Sock_Open ("clientData") is a pointer
  614.              * to some state about the pseudo-device setup.
  615.              */
  616.  
  617.             reply.status = Sock_Open((SockPdevState *) clientData, 
  618.                     requestPtr->hdr.operation == PDEV_OPEN,
  619.                     streamID,
  620.                     requestPtr->param.open.flags, 
  621.                     requestPtr->param.open.pid, 
  622.                     requestPtr->param.open.hostID, 
  623.                     requestPtr->param.open.uid, 
  624.                     -1, /* no more client ID */
  625.                     &privPtr);
  626.             free((char *)clientData);
  627.             if (reply.status == SUCCESS) {
  628.             /*
  629.              * Save the address of the socket data structure
  630.              * with the stream so subsequent requests can
  631.              * access it.
  632.              */
  633.             (void)Fs_EventHandlerChangeData(streamID,
  634.                             (ClientData)privPtr);
  635.             reply.selectBits = Sock_Select(privPtr, TRUE); 
  636.             } else {
  637.             reply.selectBits = 0;
  638.             }
  639.             PdevReply(streamID, &reply, "open");
  640.         }
  641.         break;
  642.  
  643.  
  644.         case PDEV_CLOSE:
  645.         (void) Sock_Close(privPtr);
  646.         Fs_EventHandlerDestroy(streamID);
  647.         reply.status == SUCCESS;
  648.         PdevReply(streamID, &reply, "close");
  649.         (void) close(streamID);
  650.         break;
  651.  
  652.  
  653.         /*
  654.          * The client wants data from the server.
  655.          */
  656.         case PDEV_READ:
  657.         if (privPtr->sharePtr->protoIndex == UDP_PROTO_INDEX) {
  658.             /*
  659.              * Special case optimized UDP read request handler.
  660.              * It sends its own reply
  661.              */
  662.             UDP_ReadRequest(privPtr, requestPtr, streamID);
  663.         } else {
  664.             /*
  665.              * Allocate a reply buffer to hold the data from the socket.
  666.              */
  667.             reply.replyBuf = 
  668.                 malloc((unsigned int)requestPtr->hdr.replySize);
  669.             reply.status = Sock_Read( privPtr, 
  670.                 requestPtr->hdr.replySize, reply.replyBuf,
  671.                 &reply.replySize);
  672.             /*
  673.              * Make sure we don't supply more than what was requested.
  674.              */
  675.             if (reply.replySize > replySize) {
  676.             (void) fprintf(stderr, 
  677.               "PdevRequestHandler: gave too much data for READ.\n");
  678.             }
  679.             reply.selectBits = Sock_Select(privPtr, TRUE); 
  680.             PdevReply(streamID, &reply, "read");
  681.             if (reply.replyBuf != (Address) NULL) {
  682.             free(reply.replyBuf);
  683.             }
  684.         }
  685.         break;
  686.  
  687.  
  688.         /*
  689.          * The client wants to send data to the server.
  690.          */
  691.         case PDEV_WRITE_ASYNC:
  692.         case PDEV_WRITE:
  693.         if (ips_Debug) {
  694.             (void) fprintf(stderr, "Pdev_write: %d\n", 
  695.                 requestPtr->hdr.requestSize);
  696.         }
  697.         amount = 0;
  698.         reply.replySize = sizeof(int);
  699.         reply.replyBuf = (Address)&amount;
  700.         if (requestPtr->hdr.requestSize < 0) {
  701.             reply.status = GEN_INVALID_ARG;
  702.         } else {
  703.             reply.status = Sock_Write( privPtr, 
  704.                     requestPtr->param.write.procID,
  705.                     requestPtr->hdr.requestSize,
  706.                     requestData,
  707.                     &amount);
  708.         }
  709.         if (operation == PDEV_WRITE) {
  710.             reply.selectBits = Sock_Select(privPtr, TRUE); 
  711.             PdevReply(streamID, &reply, "write");
  712.         }
  713.         break;
  714.  
  715.         case PDEV_IOCTL: {
  716.             Address outBuffer;
  717.  
  718.             if (requestPtr->hdr.requestSize < 0) {
  719.             reply.status = GEN_INVALID_ARG;
  720.             outBuffer = (Address) NULL;
  721.             } else {
  722.             outBuffer = malloc((unsigned int)requestPtr->hdr.replySize);
  723.  
  724.             reply.status = Sock_IOControl(privPtr,
  725.                     requestPtr->param.ioctl.command,
  726.                         requestPtr->param.ioctl.uid, 
  727.                     requestPtr->hdr.requestSize,
  728.                     requestData,
  729.                     requestPtr->hdr.replySize, outBuffer);
  730.             }
  731.             reply.selectBits = Sock_Select(privPtr, TRUE); 
  732.  
  733.             if (reply.status == SUCCESS) {
  734.             reply.replySize = replySize;
  735.             reply.replyBuf = outBuffer;
  736.             } else {
  737.             reply.replySize = 0;
  738.             reply.replyBuf = (Address) NULL;
  739.             }
  740.             PdevReply(streamID, &reply, "ioctl");
  741.             if (outBuffer != (Address) NULL) {
  742.             free(outBuffer);
  743.             }
  744.         }
  745.         break;
  746.  
  747.         default:
  748.         reply.status = FAILURE;
  749.         PdevReply(streamID, &reply, "??");
  750.         (void) fprintf(stderr, 
  751.             "PdevRequestHandler: unknown operation %d\n",
  752.                 requestPtr->hdr.operation);
  753.         break;
  754.     }
  755.     bufPtrs.requestFirstByte += messageSize;
  756.     }
  757.     if (operation != PDEV_CLOSE) {
  758.     status = Fs_IOControl(streamID, IOC_PDEV_SET_PTRS,
  759.         sizeof(bufPtrs), (Address) &bufPtrs, 
  760.         0, (Address) NULL);
  761.     if (status != SUCCESS){
  762.         Stat_PrintMsg(status, "set ptrs");
  763.         exit(1);
  764.     }
  765.     }
  766. }
  767.  
  768. PdevReply(streamID, replyPtr, caller)
  769.     int            streamID;
  770.     Pdev_Reply    *replyPtr;
  771.     char        *caller;
  772. {
  773.     ReturnStatus    status;
  774.  
  775.     replyPtr->magic = PDEV_REPLY_MAGIC;
  776.     replyPtr->signal = 0;
  777.     replyPtr->code = 0;
  778.     status = Fs_IOControl(streamID, IOC_PDEV_REPLY,
  779.         sizeof(*replyPtr), (Address) replyPtr, 
  780.         0, (Address) NULL);
  781.     if (status != SUCCESS && status != SYS_ARG_NOACCESS){
  782.     Stat_PrintMsg(status, caller);
  783.     exit(1);
  784.     }
  785. }
  786.  
  787.  
  788. /*
  789.  *----------------------------------------------------------------------
  790.  *
  791.  * PrintInfoAndDebug --
  792.  *
  793.  *    Calls the Stat_PrintInfo and Sock_PrintInfo routines and then
  794.  *    turns on debugging. This routine is useful when debugging
  795.  *    is normally off and something goes wrong.
  796.  *
  797.  * Results:
  798.  *    None.
  799.  *
  800.  * Side effects:
  801.  *    Information is printed and debugging turned on.
  802.  *
  803.  *----------------------------------------------------------------------
  804.  */
  805.  
  806. /*ARGSUSED*/
  807. static int
  808. PrintInfoAndDebug(sigNum, sigCode)
  809.     int        sigNum;
  810.     int        sigCode;
  811. {
  812.     Stat_PrintInfo(0,0);
  813.     Sock_PrintInfo(0,0);
  814.     ips_Debug = TRUE;
  815. }
  816.  
  817.  
  818. /*
  819.  *----------------------------------------------------------------------
  820.  *
  821.  * PrintMemStats --
  822.  *
  823.  *    Prints a summary of the memory allocator statistics.
  824.  *    Can be called as a signal handler.
  825.  *
  826.  * Results:
  827.  *    None.
  828.  *
  829.  * Side effects:
  830.  *    Statistics are printed on the standard error stream.
  831.  *
  832.  *----------------------------------------------------------------------
  833.  */
  834.  
  835. /*ARGSUSED*/
  836. static int
  837. PrintMemStats(sigNum, sigCode)
  838.     int        sigNum;        /* Ignored. */
  839.     int        sigCode;    /* Ignored. */
  840. {
  841.     Mem_PrintStats();
  842.     Mem_PrintInUse();
  843. }
  844.  
  845.  
  846. /*
  847.  *----------------------------------------------------------------------
  848.  *
  849.  * ToggleDebug --
  850.  *
  851.  *    Toggles the state of the ips_Debug flag.
  852.  *    Can be called as a signal handler.
  853.  *
  854.  * Results:
  855.  *    None.
  856.  *
  857.  * Side effects:
  858.  *    The debug flag is toggled.
  859.  *
  860.  *----------------------------------------------------------------------
  861.  */
  862.  
  863. /*ARGSUSED*/
  864. static int
  865. ToggleDebug(sigNum, sigCode)
  866.     int        sigNum;        /* Ignored. */
  867.     int        sigCode;    /* Ignored. */
  868. {
  869.     ips_Debug = !ips_Debug;
  870.     (void) fprintf(stderr, "*****  Debugging now  %s  *****\n",
  871.         ips_Debug ? "ON" : "off");
  872. }
  873.  
  874. #ifdef TEST_DISCONNECT
  875.  
  876. /*
  877.  *----------------------------------------------------------------------
  878.  *
  879.  * ToggleDisconnect --
  880.  *
  881.  *    Toggles the state of the ips_Disconnect flag.
  882.  *    Can be called as a signal handler.
  883.  *
  884.  * Results:
  885.  *    None.
  886.  *
  887.  * Side effects:
  888.  *    The  flag is toggled.
  889.  *
  890.  *----------------------------------------------------------------------
  891.  */
  892.  
  893. /*ARGSUSED*/
  894. static int
  895. ToggleDisconnect(sigNum, sigCode)
  896.     int        sigNum;        /* Ignored. */
  897.     int        sigCode;    /* Ignored. */
  898. {
  899.     ips_Disconnect = !ips_Disconnect;
  900.     (void) fprintf(stderr, "*****  Disconnect now  %s  *****\n",
  901.         ips_Disconnect ? "ON" : "off");
  902. }
  903.  
  904. #endif
  905.  
  906.  
  907. /*
  908.  *----------------------------------------------------------------------
  909.  *
  910.  * IPS_GetTimestamp --
  911.  *
  912.  *    Returns the number of milliseconds since midnight.
  913.  *
  914.  * Results:
  915.  *    The # of milliseconds since midnight.
  916.  *
  917.  * Side effects:
  918.  *    None.
  919.  *
  920.  *----------------------------------------------------------------------
  921.  */
  922.  
  923. int
  924. IPS_GetTimestamp()
  925. {
  926.     Time    time;
  927.     Time_Parts    parts;
  928.  
  929.     Sys_GetTimeOfDay(&time, (int *) NULL, (Boolean *) NULL);
  930.  
  931.     Time_ToParts(time.seconds, FALSE, &parts);
  932.     return((((parts.hours * 3600) + (parts.minutes * 60) + 
  933.          parts.seconds) * 1000) + (time.microseconds/ONE_MILLISECOND));
  934. }
  935.  
  936.  
  937. /*
  938.  *----------------------------------------------------------------------
  939.  *
  940.  * IPS_InitPacket --
  941.  *
  942.  *    Initializes a packet by allocating memory for the data and
  943.  *    packet headers and setting up the pointer to the data part
  944.  *    of the packet.
  945.  *
  946.  * Results:
  947.  *    None.
  948.  *
  949.  * Side effects:
  950.  *    Memory is allocated.
  951.  *
  952.  *----------------------------------------------------------------------
  953.  */
  954.  
  955. void
  956. IPS_InitPacket(dataLen, packetPtr)
  957.     int        dataLen;
  958.     register IPS_Packet    *packetPtr;
  959. {
  960.     packetPtr->dataLen = dataLen;
  961.     packetPtr->totalLen = dataLen + IPS_ROOM_FOR_HEADERS;
  962.     packetPtr->base = malloc((unsigned int) packetPtr->totalLen + 4);
  963.     packetPtr->dbase = packetPtr->base + 2;
  964.     packetPtr->data = packetPtr->dbase + IPS_ROOM_FOR_HEADERS;
  965.     if (((unsigned)packetPtr->data & 0x3) != 0) {
  966.     packetPtr->data += 2;
  967.     packetPtr->totalLen += 2;
  968.     }
  969. }
  970.  
  971. f1(iPtr)
  972.     int    *iPtr;
  973. {
  974.     printf("i: %x = %x\n", iPtr, *iPtr);
  975. }
  976. @
  977.  
  978.  
  979. 1.22
  980. log
  981. @Changed so it wouldn't go into an infinite loop on SYS_ARG_NOACCESS
  982. @
  983. text
  984. @d19 1
  985. a19 1
  986. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.21 89/08/10 16:44:28 douglis Exp Locker: shirriff $ SPRITE (Berkeley)";
  987. d51 1
  988. a51 1
  989. static char defaultConfigFile[100] = "/sprite/daemons/ipServer.config";
  990. @
  991.  
  992.  
  993. 1.21
  994. log
  995. @fixed bug with bind not using current uid
  996. @
  997. text
  998. @d19 1
  999. a19 1
  1000. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.20 89/08/10 16:12:19 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1001. d648 1
  1002. a648 1
  1003.     if (status != SUCCESS){
  1004. @
  1005.  
  1006.  
  1007. 1.20
  1008. log
  1009. @JKO fixes for duplicate free
  1010. @
  1011. text
  1012. @d19 1
  1013. a19 1
  1014. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.19 89/07/23 17:33:21 nelson Exp $ SPRITE (Berkeley)";
  1015. d593 1
  1016. @
  1017.  
  1018.  
  1019. 1.19
  1020. log
  1021. @Fixed alignment problem.
  1022. @
  1023. text
  1024. @d19 1
  1025. a19 1
  1026. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.18 89/06/16 08:30:54 brent Exp Locker: nelson $ SPRITE (Berkeley)";
  1027. d109 1
  1028. d111 6
  1029. d365 2
  1030. d434 1
  1031. d439 1
  1032. a439 1
  1033.         panic("PdevControlHandler: bad magic # (%x) in the request\n", 
  1034. d441 6
  1035. d448 7
  1036. d835 6
  1037. @
  1038.  
  1039.  
  1040. 1.18
  1041. log
  1042. @Fixed perror calls to print out the actual
  1043. name of the device causing trouble.
  1044. @
  1045. text
  1046. @d19 1
  1047. a19 1
  1048. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.17 89/06/02 13:54:14 brent Exp $ SPRITE (Berkeley)";
  1049. d805 2
  1050. a806 2
  1051.     packetPtr->base = packetPtr->dbase = 
  1052.             malloc((unsigned int) packetPtr->totalLen);
  1053. d808 4
  1054. @
  1055.  
  1056.  
  1057. 1.17
  1058. log
  1059. @Fixed include
  1060. @
  1061. text
  1062. @d19 1
  1063. a19 1
  1064. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.16 89/06/02 13:50:05 brent Exp Locker: brent $ SPRITE (Berkeley)";
  1065. d182 1
  1066. a182 1
  1067.     perror("main (open stream)");
  1068. d192 1
  1069. a192 1
  1070.     perror("main (open dgram)");
  1071. d202 1
  1072. a202 1
  1073.     perror("main (open raw)");
  1074. @
  1075.  
  1076.  
  1077. 1.16
  1078. log
  1079. @Updated to new pseudo-device interface
  1080. @
  1081. text
  1082. @d19 1
  1083. a19 1
  1084. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.15 89/04/10 16:33:01 mgbaker Exp Locker: brent $ SPRITE (Berkeley)";
  1085. d36 1
  1086. a36 1
  1087. #include "dev/pdev.new.h"
  1088. @
  1089.  
  1090.  
  1091. 1.15
  1092. log
  1093. @Added ifndef sun4 to inhibit certain extraneous library routines.
  1094. @
  1095. text
  1096. @d19 1
  1097. a19 1
  1098. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.14 89/03/23 09:52:17 brent Exp Locker: mgbaker $ SPRITE (Berkeley)";
  1099. d36 1
  1100. a36 1
  1101. #include "dev/pdev.h"
  1102. d619 2
  1103. @
  1104.  
  1105.  
  1106. 1.14
  1107. log
  1108. @Fixed request buffer size declarations so only main knows about
  1109. Pdev_Request's
  1110. @
  1111. text
  1112. @d19 1
  1113. a19 1
  1114. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.13 89/02/21 10:04:47 brent Exp $ SPRITE (Berkeley)";
  1115. d146 1
  1116. d152 1
  1117. @
  1118.  
  1119.  
  1120. 1.13
  1121. log
  1122. @Tuned pseudo-device interface to eliminate malloc's and copies.
  1123. Added fast paths for UDP.
  1124. @
  1125. text
  1126. @d19 1
  1127. a19 1
  1128. static char rcsid[] = "$Header: /sprite/src/daemons/ipServer/RCS/main.c,v 1.12 88/10/17 08:59:47 ouster Exp Locker: brent $ SPRITE (Berkeley)";
  1129. d316 4
  1130. a319 2
  1131.      * front to create packet headers.  We rely on this room for the
  1132.      * headers when formatting packets later.
  1133. d321 4
  1134. a324 1
  1135.     sockPdevPtr->requestBuf = (Address) malloc(sockPdevPtr->reqBufSize);
  1136. d326 1
  1137. a326 1
  1138.     bufArgs.requestBufSize = sockPdevPtr->reqBufSize - IPS_ROOM_FOR_HEADERS;
  1139. d510 1
  1140. a510 1
  1141.                 malloc((unsigned int) requestPtr->hdr.replySize);
  1142. d533 1
  1143. d551 4
  1144. a554 2
  1145.         reply.selectBits = Sock_Select(privPtr, TRUE); 
  1146.         PdevReply(streamID, &reply, "write");
  1147. @
  1148.  
  1149.  
  1150. 1.12
  1151. log
  1152. @Convert for new pdev header format.
  1153. @
  1154. text
  1155. @d19 1
  1156. a19 1
  1157. static char rcsid[] = "$Header: main.c,v 1.11 88/09/28 11:41:58 mendel Exp $ SPRITE (Berkeley)";
  1158. d29 1
  1159. d110 5
  1160. a114 5
  1161.     Mem_Bin(84);
  1162.     Mem_Bin(142);
  1163.     Mem_Bin(144);
  1164.     Mem_Bin(1514);
  1165.     Mem_Bin(4096);
  1166. d117 1
  1167. a117 1
  1168.     (void)Opt_Parse(argc, argv, optionArray, numOptions, 0);
  1169. d241 2
  1170. a242 1
  1171.  *    requests on the new stream will be handled by PdevRequestHandler().
  1172. d264 1
  1173. d267 4
  1174. d293 29
  1175. a321 4
  1176. #define BUF_SIZE    (9000+sizeof(Pdev_Request))
  1177.  
  1178.     bufArgs.requestBufAddr = (Address) malloc(BUF_SIZE);
  1179.     bufArgs.requestBufSize = BUF_SIZE;
  1180. a330 5
  1181.     if ((int)clientData == TCP_PROTO_INDEX) {
  1182.     state = TRUE;    /* on */
  1183.     } else {
  1184.     state = FALSE;    /* off */
  1185.     }
  1186. d332 1
  1187. a332 1
  1188.         sizeof(state), (Address) &state, 
  1189. a337 1
  1190.     state = FALSE;    /* off */
  1191. d339 1
  1192. a339 1
  1193.         sizeof(state), (Address) &state, 
  1194. d346 2
  1195. a347 2
  1196.     Fs_EventHandlerCreate(notify.newStreamID, FS_READABLE, PdevRequestHandler, 
  1197.                 clientData);
  1198. d388 8
  1199. d432 3
  1200. d436 4
  1201. a439 1
  1202.     switch (requestPtr->hdr.operation) {
  1203. a442 2
  1204.             ClientData    token;
  1205.  
  1206. d450 2
  1207. a451 2
  1208.              * The first arg. to Sock_Open ("clientData") is the 
  1209.              * protocol index for the socket.
  1210. d454 1
  1211. a454 1
  1212.             reply.status = Sock_Open((int) clientData, 
  1213. d462 2
  1214. a463 1
  1215.                     &token);
  1216. d470 3
  1217. a472 2
  1218.             (void)Fs_EventHandlerChangeData(streamID, token);
  1219.             reply.selectBits = Sock_Select(token, TRUE); 
  1220. d476 1
  1221. a476 1
  1222.             Reply(streamID, &reply, "open");
  1223. d482 1
  1224. a482 1
  1225.         (void) Sock_Close((PrivPtr)clientData);
  1226. d485 1
  1227. a485 1
  1228.         Reply(streamID, &reply, "close");
  1229. a486 1
  1230.         free(bufPtrs.requestAddr);
  1231. d494 6
  1232. a499 3
  1233.         if (requestPtr->hdr.replySize < 0) {
  1234.             reply.status = GEN_INVALID_ARG;
  1235.             reply.replyBuf = (Address) NULL;
  1236. d506 1
  1237. a506 1
  1238.             reply.status = Sock_Read( (PrivPtr) clientData, 
  1239. d512 1
  1240. a512 1
  1241.             if (reply.replySize > requestPtr->hdr.replySize) {
  1242. d516 5
  1243. a521 5
  1244.         reply.selectBits = Sock_Select(clientData, TRUE); 
  1245.         Reply(streamID, &reply, "read");
  1246.         if (reply.replyBuf != (Address) NULL) {
  1247.             free(reply.replyBuf);
  1248.         }
  1249. d539 1
  1250. a539 1
  1251.             reply.status = Sock_Write( (PrivPtr) clientData, 
  1252. d545 2
  1253. a546 2
  1254.         reply.selectBits = Sock_Select(clientData, TRUE); 
  1255.         Reply(streamID, &reply, "write");
  1256. d558 1
  1257. a558 2
  1258.             reply.status = Sock_IOControl(
  1259.                      (PrivPtr) clientData,
  1260. d564 1
  1261. a564 1
  1262.             reply.selectBits = Sock_Select(clientData, TRUE); 
  1263. d567 1
  1264. a567 1
  1265.             reply.replySize = requestPtr->hdr.replySize;
  1266. d573 1
  1267. a573 1
  1268.             Reply(streamID, &reply, "ioctl");
  1269. d582 1
  1270. a582 1
  1271.         Reply(streamID, &reply, "??");
  1272. d588 1
  1273. a588 1
  1274.     bufPtrs.requestFirstByte += requestPtr->hdr.messageSize;
  1275. d590 2
  1276. a591 2
  1277.     if (requestPtr->hdr.operation != PDEV_CLOSE) { 
  1278.         status = Fs_IOControl(streamID, IOC_PDEV_SET_PTRS,
  1279. d601 1
  1280. a601 1
  1281. Reply(streamID, replyPtr, caller)
  1282. a790 3
  1283.     int maxHdrSize = 
  1284.     (NET_TCP_MAX_HDR_SIZE + NET_IP_MAX_HDR_SIZE + sizeof(IPS_PacketNetHdr));
  1285.  
  1286. d792 1
  1287. a792 1
  1288.     packetPtr->totalLen = dataLen + maxHdrSize;
  1289. d795 1
  1290. a795 1
  1291.     packetPtr->data = packetPtr->dbase + maxHdrSize;
  1292. @
  1293.  
  1294.  
  1295. 1.11
  1296. log
  1297. @Added ToggleDisconnect for testing TCP lost packet recovery.
  1298. @
  1299. text
  1300. @d19 1
  1301. a19 1
  1302. static char rcsid[] = "$Header: main.c,v 1.10 88/08/30 09:53:33 brent Exp $ SPRITE (Berkeley)";
  1303. d387 1
  1304. a387 1
  1305.     if (requestPtr->magic != PDEV_REQUEST_MAGIC) {
  1306. d389 1
  1307. a389 1
  1308.             requestPtr->magic);
  1309. d399 1
  1310. a399 1
  1311.     switch (requestPtr->operation) {
  1312. d417 1
  1313. a417 1
  1314.                     requestPtr->operation == PDEV_OPEN,
  1315. d455 1
  1316. a455 1
  1317.         if (requestPtr->replySize < 0) {
  1318. d463 1
  1319. a463 1
  1320.                 malloc((unsigned int) requestPtr->replySize);
  1321. d465 2
  1322. a466 2
  1323.                     requestPtr->replySize, reply.replyBuf,
  1324.                     &reply.replySize);
  1325. d470 1
  1326. a470 1
  1327.             if (reply.replySize > requestPtr->replySize) {
  1328. d489 1
  1329. a489 1
  1330.                 requestPtr->requestSize);
  1331. d494 1
  1332. a494 1
  1333.         if (requestPtr->requestSize < 0) {
  1334. d499 2
  1335. a500 1
  1336.                     requestPtr->requestSize, requestData,
  1337. d510 1
  1338. a510 1
  1339.             if (requestPtr->requestSize < 0) {
  1340. d514 1
  1341. a514 1
  1342.             outBuffer = malloc((unsigned int)requestPtr->replySize);
  1343. d519 3
  1344. a521 2
  1345.                     requestPtr->requestSize, requestData,
  1346.                     requestPtr->replySize, outBuffer);
  1347. d526 1
  1348. a526 1
  1349.             reply.replySize = requestPtr->replySize;
  1350. d544 1
  1351. a544 1
  1352.                 requestPtr->operation);
  1353. d547 1
  1354. a547 1
  1355.     bufPtrs.requestFirstByte += requestPtr->messageSize;
  1356. d549 1
  1357. a549 1
  1358.     if (requestPtr->operation != PDEV_CLOSE) { 
  1359. @
  1360.  
  1361.  
  1362. 1.10
  1363. log
  1364. @Changed to new pseudo-device definitions
  1365. @
  1366. text
  1367. @d19 1
  1368. a19 1
  1369. static char rcsid[] = "$Header: main.c,v 1.9 88/08/26 16:34:13 mendel Exp $ SPRITE (Berkeley)";
  1370. d71 4
  1371. a74 1
  1372.  
  1373. d133 3
  1374. d137 1
  1375. d661 32
  1376. @
  1377.  
  1378.  
  1379. 1.9
  1380. log
  1381. @Patches for SPUR
  1382. @
  1383. text
  1384. @d19 1
  1385. a19 1
  1386. static char rcsid[] = "$Header: main.c,v 1.8 88/08/16 11:47:09 mendel Exp $ SPRITE (Berkeley)";
  1387. d279 1
  1388. a279 1
  1389. #define BUF_SIZE    (9000+sizeof(Pdev_NewRequest))
  1390. d350 2
  1391. a351 2
  1392.     register Pdev_NewRequest    *requestPtr;
  1393.     Pdev_NewReply    reply;
  1394. d378 1
  1395. a378 1
  1396.     requestPtr = (Pdev_NewRequest *)
  1397. d385 1
  1398. a385 1
  1399.     requestData = (Address)((Address)requestPtr + sizeof(Pdev_NewRequest));
  1400. d416 1
  1401. a416 1
  1402.                     requestPtr->param.open.clientID, 
  1403. d553 1
  1404. a553 1
  1405.     Pdev_NewReply    *replyPtr;
  1406. @
  1407.  
  1408.  
  1409. 1.8
  1410. log
  1411. @Patched bug that caused a SIG_PIPE signal to be sent to the wrong process.
  1412. @
  1413. text
  1414. @d19 1
  1415. a19 1
  1416. static char rcsid[] = "$Header: main.c,v 1.7 88/08/16 11:24:33 mendel Exp $ SPRITE (Berkeley)";
  1417. d714 3
  1418. a716 2
  1419.     packetPtr->base = malloc((unsigned int) packetPtr->totalLen);
  1420.     packetPtr->data = packetPtr->base + maxHdrSize;
  1421. @
  1422.  
  1423.  
  1424. 1.7
  1425. log
  1426. @Converted to use new libc.a
  1427. @
  1428. text
  1429. @d19 1
  1430. a19 1
  1431. static char rcsid[] = "$Header: main.c,v 1.6 88/06/26 12:14:02 mendel Exp $ SPRITE (Berkeley)";
  1432. d491 1
  1433. @
  1434.  
  1435.  
  1436. 1.6
  1437. log
  1438. @Increased the size of the Pdev buffer to 9000 bytes to allow large Sun
  1439. RPC packets for NFS.
  1440. @
  1441. text
  1442. @d19 1
  1443. a19 1
  1444. static char rcsid[] = "$Header: main.c,v 1.5 88/06/01 16:32:57 brent Exp $ SPRITE (Berkeley)";
  1445. d36 1
  1446. a36 6
  1447. #include "fs.h"
  1448. #include "io.h"
  1449. #include "time.h"
  1450. #include "sys.h"
  1451. #include "mem.h"
  1452. #include "sig.h"
  1453. d40 3
  1454. d55 4
  1455. a58 4
  1456.     {OPT_TRUE,   'd', (Address)&ips_Debug, "Turn on debugging output"},
  1457.     {OPT_STRING, 'c', (Address)&configFile, "Name of configuration file"},
  1458.     {OPT_STRING, 'i', (Address)&ipAddress, "IP address"},
  1459.     {OPT_FALSE,  'b', (Address)&detach, "Don't run in background"},
  1460. d64 2
  1461. a71 2
  1462. typedef struct Sock_PrivInfo *PrivPtr;
  1463.  
  1464. a97 1
  1465.     ReturnStatus    status;
  1466. d111 1
  1467. a111 1
  1468.     Mem_SetPrintProc(Io_PrintStream, (ClientData)io_StdErr);
  1469. d113 1
  1470. a113 1
  1471.     (void)Opt_Parse(&argc, argv, numOptions, optionArray);
  1472. a115 7
  1473.      * Run in the background if the debug flag is not set.
  1474.      */
  1475.     if (!ips_Debug && detach) {
  1476.     Proc_Detach(0);
  1477.     }
  1478.  
  1479.     /*
  1480. d124 1
  1481. a124 1
  1482.     Sys_Panic(SYS_WARNING, "main: can't set signal handler %d\n", sig); \
  1483. d137 4
  1484. a140 3
  1485.     Io_SetLineBuffer(io_StdErr, TRUE);
  1486.  
  1487.     Io_PrintStream(io_StdErr, "Sprite Internet Protocol Server: %s\n", 
  1488. d142 1
  1489. d144 2
  1490. a145 2
  1491.     if (Sys_GetHostName(sizeof(myHostName), myHostName) != SUCCESS) {
  1492.     Sys_Panic(SYS_FATAL, "Can't find my hostname\n");
  1493. d167 1
  1494. a167 1
  1495.     Fs_SetDefPerm(0777);
  1496. d169 5
  1497. a173 6
  1498.     Io_PrintString(deviceName, INET_STREAM_NAME_FORMAT, myHostName);
  1499.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_NEW_MASTER, 0666, 
  1500.             &streamID);
  1501.     if (status != SUCCESS) {
  1502.     Stat_PrintMsg(status, "main (open stream)");
  1503.     Proc_Exit(status);
  1504. d179 5
  1505. a183 6
  1506.     Io_PrintString(deviceName, INET_DGRAM_NAME_FORMAT, myHostName);
  1507.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_NEW_MASTER, 0666, 
  1508.             &streamID);
  1509.     if (status != SUCCESS) {
  1510.     Stat_PrintMsg(status, "main (open dgram)");
  1511.     Proc_Exit(status);
  1512. d189 5
  1513. a193 6
  1514.     Io_PrintString(deviceName, INET_RAW_NAME_FORMAT, myHostName);
  1515.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_NEW_MASTER, 0600, 
  1516.             &streamID);
  1517.     if (status != SUCCESS) {
  1518.     Stat_PrintMsg(status, "main (open raw)");
  1519.     Proc_Exit(status);
  1520. d199 2
  1521. a200 2
  1522.     Proc_GetIDs(&pid, NULL, NULL, NULL, NULL);
  1523.     Io_PrintStream(io_StdErr, "PID = %x\n", pid);
  1524. d204 9
  1525. d259 1
  1526. a259 2
  1527.     Sys_Panic(SYS_FATAL, "PdevControlHandler: bad event mask %x\n", 
  1528.                 eventMask);
  1529. d266 4
  1530. a269 4
  1531.     status = Fs_Read(streamID, sizeof(notify), (Address)¬ify, &amount);
  1532.     if (status != SUCCESS) {
  1533.     Stat_PrintMsg(status, "PdevControlHandler: read notify");
  1534.     Proc_Exit(status);
  1535. d271 2
  1536. a272 3
  1537.     Sys_Panic(SYS_FATAL,
  1538.         "PdevControlHandler: short read (%d) of the notify\n", amount);
  1539.     Proc_Exit(FAILURE);
  1540. d274 1
  1541. a274 2
  1542.     Sys_Panic(SYS_FATAL,
  1543.         "PdevControlHandler: bad magic # (%x) in the notify\n", 
  1544. d276 1
  1545. a276 1
  1546.     Proc_Exit(FAILURE);
  1547. d281 1
  1548. a281 1
  1549.     bufArgs.requestBufAddr = (Address) Mem_Alloc(BUF_SIZE);
  1550. d285 1
  1551. a285 1
  1552.     if (Fs_IOControl(notify.newStreamID, IOC_PDEV_SET_BUF,
  1553. d287 4
  1554. a290 3
  1555.         0, (Address) NULL) != SUCCESS){
  1556.     Stat_PrintMsg(stat_LastError, "PdevControlHandler: ioc set buf");
  1557.     Proc_Exit(stat_LastError);
  1558. d297 1
  1559. a297 1
  1560.     if (Fs_IOControl(notify.newStreamID, IOC_PDEV_BIG_WRITES,
  1561. d299 4
  1562. a302 3
  1563.         0, (Address) NULL) != SUCCESS){
  1564.     Stat_PrintMsg(stat_LastError, "PdevControlHandler: ioc big write");
  1565.     Proc_Exit(stat_LastError);
  1566. d305 1
  1567. a305 1
  1568.     if (Fs_IOControl(notify.newStreamID, IOC_PDEV_WRITE_BEHIND,
  1569. d307 4
  1570. a310 3
  1571.         0, (Address) NULL) != SUCCESS){
  1572.     Stat_PrintMsg(stat_LastError, "PdevControlHandler: ioc write behind");
  1573.     Proc_Exit(stat_LastError);
  1574. d358 1
  1575. a358 1
  1576.     Sys_Panic(SYS_FATAL, "PdevRequestHandler: bad event mask %x\n", 
  1577. d367 4
  1578. a370 4
  1579.     status = Fs_Read(streamID, sizeof(bufPtrs), (Address)&bufPtrs, &amount);
  1580.     if (status != SUCCESS) {
  1581.     Stat_PrintMsg(status, "PdevRequestHandler: get ptr ioctl");
  1582.     Proc_Exit(status);
  1583. d372 1
  1584. a372 2
  1585.     Sys_Panic(SYS_FATAL,
  1586.         "PdevControlHandler: bad magic # (%x) in the bufPtrs\n", 
  1587. d374 1
  1588. a374 1
  1589.     Proc_Exit(FAILURE);
  1590. d381 1
  1591. a381 2
  1592.         Sys_Panic(SYS_FATAL,
  1593.             "PdevControlHandler: bad magic # (%x) in the request\n", 
  1594. d383 1
  1595. a383 1
  1596.         Proc_Exit(FAILURE);
  1597. d435 1
  1598. a435 1
  1599.         (void) Sock_Close((PrivPtr) clientData);
  1600. d439 2
  1601. a440 2
  1602.         Fs_Close(streamID);
  1603.         Mem_Free(bufPtrs.requestAddr);
  1604. d455 3
  1605. a457 2
  1606.             reply.replyBuf = Mem_Alloc(requestPtr->replySize);
  1607.             reply.status = Sock_Read((PrivPtr) clientData, 
  1608. d464 1
  1609. a464 1
  1610.             Sys_Panic(SYS_WARNING, 
  1611. d471 1
  1612. a471 1
  1613.             Mem_Free(reply.replyBuf);
  1614. d481 1
  1615. a481 1
  1616.             Io_PrintStream(io_StdErr, "Pdev_write: %d\n", 
  1617. d490 1
  1618. a490 1
  1619.             reply.status = Sock_Write((PrivPtr) clientData, 
  1620. d505 1
  1621. a505 1
  1622.             outBuffer = Mem_Alloc(requestPtr->replySize);
  1623. d507 2
  1624. a508 1
  1625.             reply.status = Sock_IOControl((PrivPtr)  clientData,
  1626. d524 1
  1627. a524 1
  1628.             Mem_Free(outBuffer);
  1629. d532 1
  1630. a532 1
  1631.         Sys_Panic(SYS_WARNING, 
  1632. d539 2
  1633. a540 2
  1634.     if (requestPtr->operation != PDEV_CLOSE &&
  1635.     Fs_IOControl(streamID, IOC_PDEV_SET_PTRS,
  1636. d542 5
  1637. a546 3
  1638.         0, (Address) NULL) != SUCCESS){
  1639.     Stat_PrintMsg(stat_LastError, "set ptrs");
  1640.     Proc_Exit(stat_LastError);
  1641. d555 2
  1642. d558 1
  1643. a558 1
  1644.     if (Fs_IOControl(streamID, IOC_PDEV_REPLY,
  1645. d560 4
  1646. a563 3
  1647.         0, (Address) NULL) != SUCCESS){
  1648.     Stat_PrintMsg(stat_LastError, caller);
  1649.     Proc_Exit(stat_LastError);
  1650. d650 1
  1651. a650 1
  1652.     Io_PrintStream(io_StdErr, "*****  Debugging now  %s  *****\n",
  1653. d713 1
  1654. a713 1
  1655.     packetPtr->base = Mem_Alloc(packetPtr->totalLen);
  1656. @
  1657.  
  1658.  
  1659. 1.5
  1660. log
  1661. @Fixed the server to close its server streams after
  1662. a client closes its socket.
  1663. @
  1664. text
  1665. @d19 1
  1666. a19 1
  1667. static char rcsid[] = "$Header: main.c,v 1.4 88/05/16 09:11:28 brent Exp $ SPRITE (Berkeley)";
  1668. d284 1
  1669. a284 1
  1670. #define BUF_SIZE    (4096+sizeof(Pdev_NewRequest))
  1671. @
  1672.  
  1673.  
  1674. 1.4
  1675. log
  1676. @Conversion to new pseudo-device implementation
  1677. @
  1678. text
  1679. @d19 1
  1680. a19 1
  1681. static char rcsid[] = "$Header: main.c,v 1.3 87/12/13 18:57:23 andrew Exp $ SPRITE (Berkeley)";
  1682. d443 1
  1683. @
  1684.  
  1685.  
  1686. 1.3
  1687. log
  1688. @made myHostName global for stat.c
  1689. @
  1690. text
  1691. @d19 1
  1692. a19 1
  1693. static char rcsid[] = "$Header: main.c,v 1.2 87/10/22 21:27:09 deboor Exp $ SPRITE (Berkeley)";
  1694. d114 1
  1695. d178 2
  1696. a179 1
  1697.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_MASTER, 0666, &streamID);
  1698. d189 2
  1699. a190 1
  1700.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_MASTER, 0666, &streamID);
  1701. d200 2
  1702. a201 1
  1703.     status = Fs_Open(deviceName, FS_READ|FS_CREATE|FS_MASTER, 0600, &streamID);
  1704. a254 2
  1705.     Pdev_Request    request;
  1706.     Pdev_Reply        reply;
  1707. d256 1
  1708. a256 1
  1709.     ClientData        token;
  1710. d258 1
  1711. d284 1
  1712. a284 4
  1713.     /*
  1714.      * Read a request from the new stream. The operation must be
  1715.      * PDEV_OPEN or PDEV_DUP.
  1716.      */
  1717. d286 12
  1718. a297 43
  1719.     status = Fs_Read(notify.newStreamID, sizeof(request), (Address)&request, 
  1720.             &amount);
  1721.  
  1722.     if (status != SUCCESS) {
  1723.     Stat_PrintMsg(status, "PdevControlHandler: read request");
  1724.     Proc_Exit(status);
  1725.     } else if (amount != sizeof(request)) {
  1726.     Sys_Panic(SYS_FATAL,
  1727.         "PdevControlHandler: short read (%d) of the request\n", amount);
  1728.     Proc_Exit(FAILURE);
  1729.     } 
  1730.     
  1731.     if ((request.operation != PDEV_OPEN) &&
  1732.     (request.operation != PDEV_DUP)) {
  1733.     Sys_Panic(SYS_FATAL, "PdevControlHandler: bad request op %x\n", 
  1734.             request.operation);
  1735.     return;
  1736.     } 
  1737.  
  1738.  
  1739.     /*
  1740.      * Create a new socket structure. If the open was successful,
  1741.      * create an event handler to handle future requests on the stream.
  1742.      * Sock_Open returns a token for the new socket, which is associated
  1743.      * with the event handler for the socket's stream.
  1744.      *
  1745.      * The 1st arg. to Sock_Open ("clientData") is the protocol index for 
  1746.      * the socket.
  1747.      */
  1748.  
  1749.     reply.status = Sock_Open((int) clientData, 
  1750.             request.operation == PDEV_OPEN,
  1751.             notify.newStreamID,
  1752.             request.param.open.flags, 
  1753.             request.param.open.pid, 
  1754.             request.param.open.hostID, 
  1755.             request.param.open.uid, 
  1756.             request.param.open.clientID, 
  1757.             &token);
  1758.     if (reply.status == SUCCESS) {
  1759.     Fs_EventHandlerCreate(notify.newStreamID, FS_READABLE,
  1760.             PdevRequestHandler, token);
  1761.     reply.selectBits = Sock_Select(token, TRUE); 
  1762. d299 1
  1763. a299 1
  1764.     reply.selectBits = 0;
  1765. d301 16
  1766. a316 4
  1767.     reply.replySize = 0;
  1768.     reply.magic = PDEV_REPLY_MAGIC;
  1769.     (void) Fs_Write(notify.newStreamID, sizeof(reply), (Address) &reply,
  1770.                 &amount);
  1771. d326 6
  1772. a331 4
  1773.  *    The request is read from the pseudo-device and decoded.
  1774.  *    Depending on the request, additional data from client may be read
  1775.  *    from the pseudo-device. The socket routines may produce data
  1776.  *    which is written to the pseudo-device after the reply is written.
  1777. d352 3
  1778. a354 2
  1779.     Pdev_Request    request;
  1780.     Pdev_Reply        reply;
  1781. d356 1
  1782. a356 2
  1783.     Address        buffer;
  1784.     IPS_Packet        packet;
  1785. d365 2
  1786. a366 1
  1787.      * Read the request. Make sure it's the correct size.
  1788. d369 1
  1789. a369 1
  1790.     status = Fs_Read(streamID, sizeof(request), (Address)&request, &amount);
  1791. d371 1
  1792. a371 1
  1793.     Stat_PrintMsg(status, "PdevRequestHandler: read request");
  1794. d373 1
  1795. a373 1
  1796.     } else if (amount != sizeof(request)) {
  1797. d375 2
  1798. a376 1
  1799.         "PdevRequestHandler: short read (%d) of the request\n", amount);
  1800. a377 5
  1801.     } else if (request.magic != PDEV_REQUEST_MAGIC) {
  1802.     Sys_Panic(SYS_FATAL,
  1803.         "PdevControlHandler: bad magic # (%x) in the request\n", 
  1804.         request.magic);
  1805.     Proc_Exit(FAILURE);
  1806. d380 12
  1807. a391 4
  1808.     /*
  1809.      * Decode the operation and call a routine for the operation.
  1810.      */
  1811.     switch (request.operation) {
  1812. a392 7
  1813.     case PDEV_CLOSE:
  1814.         (void) Sock_Close((PrivPtr) clientData);
  1815.         Fs_EventHandlerDestroy(streamID);
  1816.         Fs_Close(streamID);
  1817.         break;
  1818.  
  1819.  
  1820. d394 1
  1821. a394 1
  1822.      * The client wants data from the server.
  1823. d396 1
  1824. a396 9
  1825.     case PDEV_READ:
  1826.         if (request.replySize < 0) {
  1827.         reply.status = GEN_INVALID_ARG;
  1828.         buffer = (Address) NULL;
  1829.         } else {
  1830.         /*
  1831.          * Allocate a buffer to hold the reply and the data.
  1832.          */
  1833.         buffer = Mem_Alloc(request.replySize + sizeof(reply));
  1834. a397 3
  1835.         reply.status = Sock_Read((PrivPtr) clientData, 
  1836.                     request.replySize, buffer + sizeof(reply), 
  1837.                     &reply.replySize);
  1838. d399 2
  1839. a400 8
  1840.         /*
  1841.          * Make sure we don't supply more than what was requested.
  1842.          */
  1843.         if (reply.replySize > request.replySize) {
  1844.             Sys_Panic(SYS_WARNING, 
  1845.             "PdevRequestHandler: gave too much data for READ.\n");
  1846.         }
  1847.         }
  1848. d402 10
  1849. a411 1
  1850.         reply.selectBits = Sock_Select(clientData, TRUE); 
  1851. d413 23
  1852. a435 1
  1853.         reply.magic = PDEV_REPLY_MAGIC;
  1854. a436 17
  1855.         if (reply.status == SUCCESS) {
  1856.         *(Pdev_Reply *) buffer = reply;
  1857.         status = Fs_Write(streamID, sizeof(reply)+reply.replySize, 
  1858.                     buffer, &amount);
  1859.         } else {
  1860.         reply.replySize = 0;
  1861.         status = Fs_Write(streamID, sizeof(reply), (Address) &reply,
  1862.                 &amount);
  1863.         }
  1864.         if (status != SUCCESS) {
  1865.         Sys_Panic(SYS_FATAL, 
  1866.             "PdevRequestHandler: writing READ data failed %x\n",status);
  1867.         }
  1868.         if (buffer != (Address) NULL) {
  1869.         Mem_Free(buffer);
  1870.         }
  1871.         break;
  1872. d438 7
  1873. a445 5
  1874.     /*
  1875.      * The client wants to send data to the server.
  1876.      */
  1877.     case PDEV_WRITE: {
  1878.         Pdev_EasyReply    reply;
  1879. d447 5
  1880. a451 6
  1881.         if (ips_Debug) {
  1882.             Io_PrintStream(io_StdErr, "Pdev_write: %d\n", 
  1883.                 request.requestSize);
  1884.         }
  1885.  
  1886.         if (request.requestSize < 0) {
  1887. d453 1
  1888. a453 1
  1889.             reply.data = 0;
  1890. a454 3
  1891.             Address ptr;
  1892.             int size;
  1893.  
  1894. d456 1
  1895. a456 5
  1896.              * Allocate a packet to hold the client's data.
  1897.              * If the data needs to be sent on the network, the 
  1898.              * lower-level routines can use the packet directly.
  1899.              * They are responsible for freeing the memory allocated
  1900.              * to the packet.
  1901. d458 11
  1902. a468 18
  1903.             IPS_InitPacket(request.requestSize, &packet);
  1904.  
  1905.             ptr = packet.data;
  1906.             size = request.requestSize;
  1907.  
  1908.             do {
  1909.             status = Fs_Read(streamID, size, ptr, &amount);
  1910.             if (status != SUCCESS) {
  1911.                 Sys_Panic(SYS_FATAL, 
  1912.                "PdevRequestHandler: reading WRITE data failed %x\n",
  1913.                  status);
  1914.             }
  1915.             size -= amount;
  1916.             ptr  += amount;
  1917.             } while (size > 0);
  1918.  
  1919.             reply.status = Sock_Write((PrivPtr) clientData, 
  1920.                     &packet, &reply.data);
  1921. a469 1
  1922.  
  1923. d471 5
  1924. a476 4
  1925.         reply.replySize = sizeof(int);
  1926.         reply.magic = PDEV_REPLY_MAGIC;
  1927.         status = Fs_Write(streamID, sizeof(reply), (Address) &reply, 
  1928.                     &amount);
  1929. d478 7
  1930. a484 4
  1931.         if (status != SUCCESS) {
  1932.             Sys_Panic(SYS_FATAL, 
  1933.              "PdevRequestHandler: writing WRITE reply failed %x\n", 
  1934.              status);
  1935. d486 4
  1936. a489 8
  1937.         }
  1938.         break;
  1939.  
  1940.     case PDEV_IOCTL: {
  1941.         Address inBuffer;
  1942.         Address outBuffer;
  1943.  
  1944.         if (request.requestSize < 0) {
  1945. a490 3
  1946.             inBuffer  = (Address) NULL;
  1947.             outBuffer = (Address) NULL;
  1948.  
  1949. d492 3
  1950. a494 14
  1951.             if (request.requestSize == 0) {
  1952.             inBuffer = (Address) NULL;
  1953.             } else {
  1954.             inBuffer = Mem_Alloc(request.requestSize);
  1955.             status = Fs_Read(streamID, request.requestSize, 
  1956.                         inBuffer, &amount);
  1957.             }
  1958.             outBuffer = Mem_Alloc(sizeof(reply) + request.replySize);
  1959.  
  1960.             reply.status = Sock_IOControl((PrivPtr)  clientData,
  1961.                     request.param.ioctl.command,
  1962.                     request.requestSize, inBuffer,
  1963.                     request.replySize, 
  1964.                     outBuffer + sizeof(reply));
  1965. d497 2
  1966. d500 2
  1967. a501 12
  1968.         reply.magic = PDEV_REPLY_MAGIC;
  1969.         if (reply.status == SUCCESS) {
  1970.             reply.replySize = request.replySize;
  1971.             *(Pdev_Reply *) outBuffer = reply;
  1972.             status = Fs_Write(streamID, 
  1973.                     sizeof(reply) + reply.replySize,
  1974.                     outBuffer, &amount);
  1975.         } else {
  1976.             reply.replySize = 0;
  1977.             status = Fs_Write(streamID, sizeof(reply), 
  1978.                     (Address) &reply, &amount);
  1979.         }
  1980. d503 5
  1981. a507 5
  1982.         if (status != SUCCESS) {
  1983.             Sys_Panic(SYS_FATAL, 
  1984.             "PdevRequestHandler: writing IOC reply failed %x\n", 
  1985.             status);
  1986.         }
  1987. d509 18
  1988. a526 2
  1989.         if (inBuffer != (Address) NULL) {
  1990.             Mem_Free(inBuffer);
  1991. d528 1
  1992. a528 5
  1993.         if (outBuffer != (Address) NULL) {
  1994.             Mem_Free(outBuffer);
  1995.         }
  1996.         }
  1997.         break;
  1998. d530 18
  1999. d549 11
  2000. a559 12
  2001.  
  2002.         break;
  2003.  
  2004.     default:
  2005.         reply.status = FAILURE;
  2006.         reply.replySize = 0;
  2007.         reply.magic = PDEV_REPLY_MAGIC;
  2008.         (void) Fs_Write(streamID, sizeof(reply), (Address) &reply, 
  2009.                     &amount);
  2010.         Sys_Panic(SYS_WARNING, "PdevRequestHandler: unknown operation %d\n",
  2011.                 request.operation);
  2012.         break;
  2013. d617 1
  2014. a617 1
  2015.     Mem_PrintStats(Io_PrintStream, (ClientData) io_StdErr);
  2016. @
  2017.  
  2018.  
  2019. 1.2
  2020. log
  2021. @Nuked debug handler to print number of times system calls are executed
  2022. @
  2023. text
  2024. @d19 1
  2025. a19 1
  2026. static char rcsid[] = "$Header: main.c,v 1.1 87/10/19 15:58:56 deboor Exp $ SPRITE (Berkeley)";
  2027. d64 1
  2028. a103 1
  2029.     char        myHostName[100];
  2030. @
  2031.  
  2032.  
  2033. 1.1
  2034. log
  2035. @Initial revision
  2036. @
  2037. text
  2038. @d19 1
  2039. a19 1
  2040. static char rcsid[] = "$Header: main.c,v 6.0 87/09/09 01:17:22 andrew Stable $ SPRITE (Berkeley)";
  2041. d105 1
  2042. d107 1
  2043. d140 1
  2044. d142 1
  2045. @
  2046.